package com.etoak.controller;

import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Cart;
import com.etoak.service.CartService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    CartService cartService;
    //添加或修改购物车
    @PostMapping
    public ResultVO<Object> saveOrUpdate(@Valid @RequestBody Cart cart){
        cartService.saveOrUpdate(cart);
        return ResultVO.success();
    }
    //查询购物车中的菜品信息
    @GetMapping
    public ResultVO<List<Cart>> list(){
        List<Cart> cartList = cartService.list();
        return ResultVO.success(cartList);
    }
    //删除购物车中的菜品
    @DeleteMapping("/{ids}")
    public ResultVO<Object> delete(@PathVariable List<String> ids){
        cartService.delete(ids);
        return ResultVO.success();
    }

}
